import { param2Obj } from '@/utils'

const userMap = {
  SuperAdmin: {
    roles: ['SuperAdmin'],
    token: 'SuperAdmin',
    introduction: '我是超级管理员',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  Admin: {
    roles: ['Admin'],
    token: 'Admin',
    introduction: '我是管理员',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Admin'
  },
  School: {
    roles: ['School'],
    token: 'School',
    introduction: '我是学校',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'School'
  },
  Teacher: {
    roles: ['Teacher'],
    token: 'Teacher',
    introduction: '我是教师',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Teacher'
  }
}

export default {
  loginByEmail: config => {
    const { email } = JSON.parse(config.body)
    return userMap[email]
  },
  loginByUsername: config => {
    const { username } = JSON.parse(config.body)
    return userMap[username]
  },
  getUserInfo: config => {
    const { token } = param2Obj(config.url)
    if (userMap[token]) {
      return userMap[token]
    } else {
      return false
    }
  },
  logout: () => 'success'
}
